import { get, post, del, put } from "@/utils/request";
import {
  type foodAddParams,
  type foodPriceAddParams,
  type foodsListData,
  type foodsListParams,
  type foodsListReturn,
  type foodsPriceData,
  type foodsPriceListReturn,
} from "./type";

// 食材列表
export const foodsList = (data: foodsListParams) => {
  return get<foodsListParams, foodsListReturn>("/api/foods/list", data);
};

// 食材添加
export const foodsAdd = (data: foodAddParams) => {
  return post<foodAddParams, foodsListData>("/api/foods/add", data);
};

// 食材编辑
export const foodsEdit = (data: foodAddParams) => {
  return put<foodAddParams, foodsListData>("/api/foods/update", data);
};

// 删除
export const foodsDel = (id: number) => {
  return del<number, null>(`/api/foods/delete/${id}`);
};

// 批量删除
export const foodsBatchDel = (ids: number[]) => {
  return post<number[], null>("/api/foods/deleteAll", ids);
};

// 添加食材价格
export const foodsPriceAdd = (data: foodPriceAddParams) => {
  return post<foodPriceAddParams, foodsPriceData>("/api/foodprice/add", data);
};

// 修改食材价格
export const foodsPriceEdit = (data: foodPriceAddParams) => {
  return put<foodPriceAddParams, foodsPriceData>("/api/foodprice/update", data);
};

// 根据食材id获取食材信息
export const foodsGet = (id: number) => {
  return get<number, foodsListData>(`/api/foods/get/${id}`);
};

// 根据食材id获取价格列表
export const foodsPriceList = (id: number) => {
  return get<number, foodsPriceListReturn>(`/api/foodprice/list/${id}`);
};
